Skip to content

Conversation

@2shrestha22
Copy link
Contributor

@2shrestha22 2shrestha22 commented Nov 27, 2024

Pull Request

Issue

Closes: #1022

Approach

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of HTTP client exceptions and refined exception parsing to produce consistent, properly formatted error responses with more reliable messages and codes.
  • Refactor

    • Consolidated internal SDK modules to simplify the library surface and internal structure.
  • Tests

    • Added unit tests covering various exception scenarios to validate error parsing and preservation of original exceptions.
  • Documentation

    • Added changelog entry for v8.0.1.
  • Chores

    • Bumped package version to 8.0.1.

✏️ Tip: You can customize this high-level summary in your review settings.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Nov 27, 2024

🚀 Thanks for opening this pull request!

@mbfakourii
Copy link
Member

@mtrezza

Can you please run CI?

@mtrezza
Copy link
Member

mtrezza commented Nov 30, 2024

@mbfakourii done

@codecov
Copy link

codecov bot commented Nov 30, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.98%. Comparing base (20efcdf) to head (3d06272).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1021      +/-   ##
==========================================
+ Coverage   43.72%   43.98%   +0.26%     
==========================================
  Files          61       61              
  Lines        3465     3469       +4     
==========================================
+ Hits         1515     1526      +11     
+ Misses       1950     1943       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtrezza mtrezza changed the title handle http ClientException fix: http client exception not handled properly resulting in incorrect error log Dec 4, 2024
@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: http client exception not handled properly resulting in incorrect error log fix: Http client exception not handled properly resulting in incorrect error log Dec 4, 2024
@mtrezza mtrezza changed the title fix: Http client exception not handled properly resulting in incorrect error log fix: Http client exception not handled properly resulting in incorrectly formatted error Dec 4, 2024
@mtrezza
Copy link
Member

mtrezza commented Dec 4, 2024

I rephrased the PR title; not sure whether it accurately describes the issue, could you please review?

@2shrestha22
Copy link
Contributor Author

I think it's better.

@mtrezza
Copy link
Member

mtrezza commented Dec 8, 2024

There is still an open review discussion and the changelog entry + version bump is missing in the PR. See other PRs on how they are done. Then we can go ahead and merge.

@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2025

📝 Walkthrough

Walkthrough

Added an http import and removed many part directives from the main Dart library file; added explicit handling for http.ClientException and refined DioException parsing in the parse-exception response builder; bumped package version and added unit tests for exception handling.

Changes

Cohort / File(s) Summary
Library entry changes
packages/dart/lib/parse_server_sdk.dart
Added import 'package:http/http.dart'; and removed numerous part directives that previously split the library into multiple parts.
Exception handling
packages/dart/lib/src/objects/response/parse_exception_response.dart
Added handling for http.ClientException in buildParseResponseWithException; refined DioException handling to attempt parsing an integer code from the response before falling back to statusCode; returns ParseResponse with ParseError including the original exception.
Tests
packages/dart/test/src/objects/response/parse_exception_response_test.dart
Added unit tests covering DioException (JSON and non-JSON bodies), http.ClientException, and generic Exception paths for buildParseResponseWithException.
Metadata / docs
packages/dart/CHANGELOG.md, packages/dart/pubspec.yaml
Bumped package version to 8.0.1 and added changelog entry documenting the ClientException fix.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SDK as Parse SDK
  participant HTTP as http.Client
  participant Builder as buildParseResponseWithException

  Client->>SDK: perform request
  SDK->>HTTP: send request
  alt http.ClientException thrown
    HTTP-->>SDK: throws ClientException
    SDK->>Builder: buildParseResponseWithException(ClientException)
    Builder-->>SDK: ParseResponse{ error: ParseError(message, exception) }
  else DioException thrown
    HTTP-->>SDK: throws DioException
    SDK->>Builder: buildParseResponseWithException(DioException)
    Builder-->>SDK: ParseResponse{ error: ParseError(parsedMessage, parsedCode, exception) }
  else other Exception
    HTTP-->>SDK: throws Exception
    SDK->>Builder: buildParseResponseWithException(Exception)
    Builder-->>SDK: ParseResponse{ error: ParseError(message, exception) }
  end
  SDK-->>Client: return ParseResponse (error)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect parse_server_sdk.dart to ensure removed part directives didn't drop exported symbols or change public API composition.
  • Review buildParseResponseWithException changes for correct preservation of the original exception, numeric code parsing, and consistent ParseError shaping.
  • Run and review the added tests in parse_exception_response_test.dart to confirm coverage and expected behavior.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly describes the main fix being implemented - handling HTTP client exceptions to produce properly formatted errors.
Description check ✅ Passed The PR description includes the required template structure with the linked issue (#1022), marks tasks as completed, but lacks a detailed Approach section explaining the implementation.
Linked Issues check ✅ Passed The PR successfully addresses issue #1022 by adding ClientException handling in buildParseResponseWithException with comprehensive tests and changelog entry.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing HTTP client exception handling. The import addition and part directive removal in parse_server_sdk.dart appear to be refactoring, which is minimal and necessary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@2shrestha22
Copy link
Contributor Author

There is still an open review discussion and the changelog entry + version bump is missing in the PR. See other PRs on how they are done. Then we can go ahead and merge.

I thought changelog and version bump should be maintained on release instead of PR merge.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/dart/lib/parse_server_sdk.dart (1)

12-12: Narrow http import to avoid potential symbol clashes with dio

Given this is the root library for many part files and you already import package:dio/dio.dart, bringing in all of package:http/http.dart risks name clashes (e.g., Response) in any part that uses unqualified types.

Since the only thing needed here is ClientException for buildParseResponseWithException, consider narrowing the import:

-import 'package:http/http.dart';
+import 'package:http/http.dart' show ClientException;

This keeps the namespace clean while still enabling the new exception handling.

Please double‑check that no other symbols from http are used anywhere in the parts of this library before applying this change.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec71870 and 54a0f68.

📒 Files selected for processing (2)
  • packages/dart/lib/parse_server_sdk.dart (1 hunks)
  • packages/dart/lib/src/objects/response/parse_exception_response.dart (1 hunks)
🔇 Additional comments (1)
packages/dart/lib/src/objects/response/parse_exception_response.dart (1)

25-29: ClientException handling looks correct and aligns with existing patterns

The new ClientException branch cleanly maps http client errors into a ParseError, consistent with the generic fallback (no explicit error code, message taken from the exception) and separate from the richer DioException handling above.

Functionally this should resolve the issue where ClientException.toString() was previously exposed.

Please confirm:

  • That you have a test covering a thrown ClientException and asserting the resulting ParseResponse.error.message.
  • That no additional metadata (e.g., a specific error code) is needed for ClientException beyond what the generic fallback already provided.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 15, 2025
@mtrezza
Copy link
Member

mtrezza commented Nov 20, 2025

@2shrestha22 each PR merge triggers a release.

@2shrestha22
Copy link
Contributor Author

@2shrestha22 each PR merge triggers a release.

updated

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 22, 2025
@mtrezza mtrezza changed the title fix: Http client exception not handled properly resulting in incorrectly formatted error fix: HTTP client exception not handled properly resulting in incorrectly formatted error Nov 22, 2025
mtrezza
mtrezza previously approved these changes Nov 23, 2025
@mtrezza
Copy link
Member

mtrezza commented Nov 23, 2025

Fixed the CI issues in #1046, should all pass now

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/dart/lib/src/objects/response/parse_exception_response.dart (1)

26-30: ClientException mapping fixes the bug; consider a more specific error code

Handling ClientException explicitly and surfacing exception.message directly addresses the original issue and keeps the original exception attached, which is good.

If you want to distinguish network/client errors from generic ones, you could optionally set a dedicated ParseError code here (for example a “connection failed” constant, if available in this SDK) instead of relying on the default otherCause. That would make it easier for callers to branch on network vs. server errors.

Example (only if you decide to specialize the code):

-  if (exception is ClientException) {
-    return ParseResponse(
-      error: ParseError(message: exception.message, exception: exception),
-    );
-  }
+  if (exception is ClientException) {
+    return ParseResponse(
+      error: ParseError(
+        message: exception.message,
+        exception: exception,
+        // Consider using a dedicated connection/network error code here.
+      ),
+    );
+  }

This is optional and can be deferred.

packages/dart/test/src/objects/response/parse_exception_response_test.dart (1)

1-72: Good coverage of exception-mapping behavior; consider one more small case

These tests nicely pin down the behaviors for:

  • DioException with JSON payload (message + string code),
  • DioException with non-JSON body (status message/code fallback),
  • http ClientException,
  • generic Exception,

and they verify that the original exception object is preserved in all cases. This is exactly what the production code is doing.

If you want one more safety net, you could add a variant of the first test where code is an integer ('code': 123) to guard against future regressions in the numeric-path handling, but that’s strictly a nice-to-have.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd37a5e and 3d06272.

📒 Files selected for processing (2)
  • packages/dart/lib/src/objects/response/parse_exception_response.dart (2 hunks)
  • packages/dart/test/src/objects/response/parse_exception_response_test.dart (1 hunks)
🔇 Additional comments (1)
packages/dart/lib/src/objects/response/parse_exception_response.dart (1)

14-23: DioException error code parsing is correct and improves robustness

Using codeString plus int.tryParse before falling back to statusCode gives you a clean numeric error code whether the server sends "123" or 123, and preserves the existing fallback to ParseError.otherCause when nothing is available. The logic is sound and aligns with the new tests.

@mtrezza
Copy link
Member

mtrezza commented Nov 23, 2025

Interesting, were there still some failing tests?

@2shrestha22
Copy link
Contributor Author

Interesting, were there still some failing tests?
There was not any test written initially that's why code coverage was failing.

@mtrezza
Copy link
Member

mtrezza commented Nov 23, 2025

Got it, is this ready for merge now?

@2shrestha22
Copy link
Contributor Author

Yes ready to merge

@mtrezza mtrezza merged commit 4f20640 into parse-community:master Nov 23, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http ClientException is not handled

3 participants